package com.spt.springbootzhsx.controller;

import com.spt.springbootzhsx.dao.PlanDao;
import com.spt.springbootzhsx.entity.Plan;
import com.spt.springbootzhsx.entity.back.PlanBack;
import com.spt.springbootzhsx.service.PlanService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.beans.SimpleBeanInfo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

@RestController
@RequestMapping(value="/plan")
public class PlanController {
    @Autowired
    private PlanService planService;

    @GetMapping(value="/getAllPlan")
    public ArrayList<PlanBack> getAllPlan(){
        return planService.getAllPlan();
    }

    @GetMapping(value="/getAllPlanNow")
    public ArrayList<PlanBack> getAllPlanNow(){
        return planService.getAllPlanNow();
    }

    @GetMapping(value = "/getPlanByMname/{mname}")
    public ArrayList<PlanBack> getPlanByMname(@PathVariable("mname") String mname){
        return planService.getPlanByMname(mname);
    }

    @GetMapping(value = "/getPlanByMnameNow/{mname}")
    public ArrayList<PlanBack> getPlanByMnameNow(@PathVariable("mname") String mname){
        return planService.getPlanByMnameNow(mname);
    }

    @PostMapping(value="/addPlan")
    public String addPlan(@RequestBody Plan plan){
        return planService.addPlan(plan);
    }

    @GetMapping(value="deletePlan/{pid}")
    public String deletePlan(@PathVariable("pid") Integer pid){
        return planService.deletePlan(pid);
    }

    @PostMapping(value="/updatePlan")
    public String updatePlan(@RequestBody Plan plan){
        return planService.updatePlan(plan);
    }

    //根据电影名或者影厅搜索场次
    @GetMapping(value="/getPlanByMnameOrCname/{key}")
    public ArrayList<PlanBack> getPlanByMnameOrCname(@PathVariable("key") String key){
        return planService.getPlanByMnameOrCname(key);
    }

    //根据电影名或者影厅搜索当前时间以后的场次
    @GetMapping(value="/getPlanByMnameOrCnameNow/{key}")
    public ArrayList<PlanBack> getPlanByMnameOrCnameNow(@PathVariable("key") String key){
        return planService.getPlanByMnameOrCnameNow(key);
    }

    @GetMapping(value="/getPlanByMidAndDate/{mid}/{date}")
    public ArrayList<PlanBack> getPlanByMnameAndDate(@PathVariable("mid") Integer mid,@PathVariable("date") long date){
        return planService.getPlanByMidAndDate(mid,date);
    }

   @GetMapping(value="/getPlanByPid/{pid}")
    public PlanBack getPlanByPid(@PathVariable("pid") Integer pid){
        return planService.getPlanByPid(pid);
   }

}
